package com.bbs.detai1713.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

    @Data
    public class User implements UserDetails {
        long userId;
        String username,password,nickName,headImage;
        int age,roleId;
        @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
        Timestamp registerDate;
        Date birthday;
        Role role;


        @Override
        public Collection<? extends GrantedAuthority> getAuthorities() {
            List<SimpleGrantedAuthority> authorities=new ArrayList<>();
            authorities.add(new SimpleGrantedAuthority(role.getName()));
            return authorities;
        }

        @Override
        public String getPassword() {
            return password;
        }

        @Override
        public String getUsername() {
            return username;
        }

        @Override
        public boolean isAccountNonExpired(){
            return true;
        }
        @Override
        public boolean isAccountNonLocked(){
            return true;
        }
        @Override
        public boolean isCredentialsNonExpired(){
            return true;
        }
        @Override
        public boolean isEnabled(){
            return true;
        }
}
